﻿//namespace的实现
var AB = {};

AB.namespace = function () {
    var a = arguments, o = null, i, j, d, rt;
    for (i = 0; i < a.length; ++i) {
        d = a[i].split(".");
        rt = d[0];
        eval("if (typeof (" + rt + ") == 'undefined'){" + rt + "= {};} o = " + rt + ";");
        for (j = 1; j < d.length; ++j) {
            o[d[j]] = o[d[j]] || {};
            o = o[d[j]];
        }
    }
};

//--页面事件
var PageReady = function ()
{ }

//--控件事件
var formStoreLoaded = function (store, records, formObj) {
    if (!formObj || formObj == null || formObj == "")
    { return false; }
    if (records.length > 0) {
        formObj.form.loadRecord(records[0]);
    }
    else {
        formObj.form.reset();
    }
    formObj.el.unmask();
}

var getGridRowClickRecord = function (grid, rowindex, evenobj) {
    var store = grid.getStore();
    var record = grid.getSelectionModel().getSelected();
    return record;
}

var failureHandler = function (form, action, failureCallBack) {
    var msg = '';
    if (action.failureType == "client" || (action.result && action.result.errors && action.result.errors.length > 0)) {
        msg = "请检查表单项是否已按要求填好";
    } else if (action.result && action.result.extraParams.msg) {
        msg = action.result.extraParams.msg;
    } else if (action.response) {
        msg = action.response.responseText;
    } else if (action.responseText) {
        msg = action.responseText;
    } else if (action.errorMessage) {
        msg = action.errorMessage
    }
    Ext.Msg.show({
        title: '操作失败',
        msg: msg,
        buttons: Ext.Msg.OK,
        icon: Ext.Msg.ERROR,
        fn: failureCallBack
    });
}

var successHandler = function (form, action, successCallBack) {
    Ext.MessageBox.alert('系统信息', '操作成功!', successCallBack);
    recordChanged = true;
}


var isTimeOut = function (response) {
    if ((response.status == '205' || response.status == 205) && (response.getAllResponseHeaders().indexOf("Sessionstatus") > 0)) {
        return true;
    } else {
        return false;
    }
}


var ajaxFailureHandler = function (response) {
    Ext.Msg.show({
        title: '操作失败',
        msg: response.errorMessage,
        buttons: Ext.Msg.OK,
        icon: Ext.Msg.ERROR
    });
}


